\doxysection{x\+Stream\+Buffer\+Send }
\hypertarget{group__x_stream_buffer_send}{}\label{group__x_stream_buffer_send}\index{xStreamBufferSend@{xStreamBufferSend}}
\doxylink{stream__buffer_8h_source}{stream\+\_\+buffer.\+h}


\begin{DoxyPre}
size\_t xStreamBufferSend( StreamBufferHandle\_t xStreamBuffer,                           const void *pvTxData,                           size\_t xDataLengthBytes,                           TickType\_t xTicksToWait );
\end{DoxyPre}


Sends bytes to a stream buffer. The bytes are copied into the stream buffer.

{\itshape {\bfseries{NOTE}}}\+: Uniquely among Free\+RTOS objects, the stream buffer implementation (so also the message buffer implementation, as message buffers are built on top of stream buffers) assumes there is only one task or interrupt that will write to the buffer (the writer), and only one task or interrupt that will read from the buffer (the reader). It is safe for the writer and reader to be different tasks or interrupts, but, unlike other Free\+RTOS objects, it is not safe to have multiple different writers or multiple different readers. If there are to be multiple different writers then the application writer must place each call to a writing API function (such as x\+Stream\+Buffer\+Send()) inside a critical section and set the send block time to 0. Likewise, if there are to be multiple different readers then the application writer must place each call to a reading API function (such as x\+Stream\+Buffer\+Receive()) inside a critical section and set the receive block time to 0.

Use x\+Stream\+Buffer\+Send() to write to a stream buffer from a task. Use x\+Stream\+Buffer\+Send\+From\+ISR() to write to a stream buffer from an interrupt service routine (ISR).


\begin{DoxyParams}{Parameters}
{\em x\+Stream\+Buffer} & The handle of the stream buffer to which a stream is being sent.\\
\hline
{\em pv\+Tx\+Data} & A pointer to the buffer that holds the bytes to be copied into the stream buffer.\\
\hline
{\em x\+Data\+Length\+Bytes} & The maximum number of bytes to copy from pv\+Tx\+Data into the stream buffer.\\
\hline
{\em x\+Ticks\+To\+Wait} & The maximum amount of time the task should remain in the Blocked state to wait for enough space to become available in the stream buffer, should the stream buffer contain too little space to hold the another x\+Data\+Length\+Bytes bytes. The block time is specified in tick periods, so the absolute time it represents is dependent on the tick frequency. The macro pd\+MS\+\_\+\+TO\+\_\+\+TICKS() can be used to convert a time specified in milliseconds into a time specified in ticks. Setting x\+Ticks\+To\+Wait to port\+MAX\+\_\+\+DELAY will cause the task to wait indefinitely (without timing out), provided INCLUDE\+\_\+v\+Task\+Suspend is set to 1 in \doxylink{_free_r_t_o_s_config_8h_source}{Free\+RTOSConfig.\+h}. If a task times out before it can write all x\+Data\+Length\+Bytes into the buffer it will still write as many bytes as possible. A task does not use any CPU time when it is in the blocked state.\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The number of bytes written to the stream buffer. If a task times out before it can write all x\+Data\+Length\+Bytes into the buffer it will still write as many bytes as possible.
\end{DoxyReturn}
Example use\+: 
\begin{DoxyPre}
void vAFunction( StreamBufferHandle\_t xStreamBuffer )
\{
size\_t xBytesSent;
uint8\_t ucArrayToSend[] = \{ 0, 1, 2, 3 \};
char *pcStringToSend = "{}String to send"{};
const TickType\_t x100ms = pdMS\_TO\_TICKS( 100 );

    // Send an array to the stream buffer, blocking for a maximum of 100ms to
    // wait for enough space to be available in the stream buffer.
    xBytesSent = xStreamBufferSend( xStreamBuffer, ( void * ) ucArrayToSend, sizeof( ucArrayToSend ), x100ms );

    if( xBytesSent != sizeof( ucArrayToSend ) )
    \{
        // The call to xStreamBufferSend() times out before there was enough
        // space in the buffer for the data to be written, but it did
        // successfully write xBytesSent bytes.
    \}

    // Send the string to the stream buffer.  Return immediately if there is not
    // enough space in the buffer.
    xBytesSent = xStreamBufferSend( xStreamBuffer, ( void * ) pcStringToSend, strlen( pcStringToSend ), 0 );

    if( xBytesSent != strlen( pcStringToSend ) )
    \{
        // The entire string could not be added to the stream buffer because
        // there was not enough free space in the buffer, but xBytesSent bytes
        // were sent.  Could try again to send the remaining bytes.
    \}
\}
\end{DoxyPre}
 